home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / quicktime for java / imagecompositing / src / javatext.java < prev    next >
Encoding:
Java Source  |  2000-09-28  |  1.6 KB  |  49 lines

  1. /*
  2.  * QuickTime for Java SDK Sample Code
  3.  
  4.    Usage subject to restrictions in SDK License Agreement
  5.  * Copyright: © 1996-1999 Apple Computer, Inc.
  6.  
  7.  */
  8. import java.awt.*;
  9. import quicktime.app.image.*;
  10. import java.util.*;
  11.  
  12. class JavaText implements Paintable {
  13.     Font font = new Font ("Helvetica", Font.PLAIN, 32);
  14.     int width, height;
  15.     Rectangle[] r = new Rectangle[1];
  16.     Random rand = new Random();    //use this for generating random text colour
  17.     
  18.     public void newSizeNotified (QTImageDrawer drawer, Dimension d) {
  19.         width = d.width;
  20.         height = d.height;
  21.         r[0] = new Rectangle (width, height);
  22.     }
  23.     
  24.     /**
  25.      * Paint on the graphics. The supplied component is the component from which
  26.      * the graphics object was derived or related to and is also the component
  27.      * that is the object that paint was called upon that has called this method.
  28.      * The Graphics object is what you should paint on.
  29.      * This maybe an on or off screen graphics.
  30.      * You should not cache this graphics object as it can be different
  31.      * between different calls.
  32.      * @param comp the component from which the Graphics object was derived or 
  33.      * related too.
  34.      * @param g the graphics to paint on.
  35.      */
  36.     public Rectangle[] paint (Graphics g) {        
  37.         Color c = new Color (255, Math.abs(rand.nextInt()) % 256, Math.abs(rand.nextInt()) % 256);
  38.         System.out.println ("New TextColor:" + c);
  39.         g.setColor (c);
  40.         g.setFont (font);
  41.         g.drawString ("Java Text", 5, 30);
  42.         g.setColor (Color.red);
  43.         g.drawRect (0, 0, width-1, height-1);
  44.         g.drawRect (1, 1, width-3, height-3);
  45.         g.drawRect (2, 2, width-5, height-5);
  46.         return r;
  47.     }
  48. }
  49.